#include "promptbtnitem.h"
#include <QPainter>
#include "global/globalvar.h"
#include <QDebug>

#define PROBTN_NORMAL_COLOR     QColor(245,222,179)
#define PROBTN_DISABLE_COLOR    QColor(169,169,169)
#define PROBTN_ANGLE_COLOR      QColor(105,105,105)

PromptBtnItem::PromptBtnItem()
{
}

void PromptBtnItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    painter->save();

    QPainterPath path;
    path.addEllipse(QPointF(20.0f,20.0f),20.0f,20.0f);

    SetCircleColor();

    painter->fillPath(path,QBrush(m_color));

    QPolygonF polygon;
    polygon << QPointF(4.68f, 30.0f) << QPointF(20.0f, 3.0f)
            << QPointF(35.32f, 30.0f) << QPointF(4.68f, 30.0f);

    QPainterPath pathPolygon;
    pathPolygon.addPolygon(polygon);
    QPen p(PROBTN_ANGLE_COLOR);
    p.setWidth(2);
    painter->setPen(p);
    painter->drawPath(pathPolygon);

    painter->drawText(QRectF(0.0f,0.0f,40.0f,40.0f),
                      Qt::AlignCenter,
                      QString("%1").arg(globalvar::m_logic.m_iPromptTime));

    painter->restore();
}

QRectF PromptBtnItem::boundingRect() const
{
    return QRectF(0.0f,0.0f,40.0f,40.0f);
}

void PromptBtnItem::SetCircleColor()
{
    if(globalvar::m_logic.m_bPromptBtnEnable)
        m_color = PROBTN_NORMAL_COLOR;
    else
        m_color = PROBTN_DISABLE_COLOR;
}
